/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.iscte.iul.dcti.pa.gspas.util;

/**
 * @author Gedsimon Pereira - 58554
 * @contact gspas@iscte.pt
 *
 *
 */
public enum BeanType {

    GET,
    SET,
    IS,
    ADD,
    NONE;

    public static BeanType get(String name) {
        if (name.startsWith("set")) {
            return SET;
        } else if (name.startsWith("get")) {
            return GET;
        } else if (name.startsWith("is")) {
            return IS;
        } else if (name.startsWith("add")) {
            return ADD;
        } else {
            return NONE;
        }
    }

    public boolean isGetter() {
        switch (this) {
            case GET:
            case IS:
                return true;
            default:
                return false;
        }
    }

    public boolean isSetter() {
        switch (this) {
            case SET:
                return true;
            default:
                return false;
        }
    }

    public boolean isAdd() {
        return this == ADD;
    }

    public String getMethodProperty(String beanMethodName) {
        int startIndex = 0;
        String suffix = "";
        switch (this) {
            case GET:
            case SET:
                startIndex = 3;
                break;
            case ADD:
                startIndex = 0;
                //suffix = "s";
                break;
            case IS:
                startIndex = 2;
            default:
                break;
        }
        return beanMethodName.substring(startIndex) + suffix;
    }
}
